{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:26:34.604840Z",
     "start_time": "2019-12-09T19:26:33.827779Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e10637f292d544c68486de6ab7aff72f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Text(value='', description='Enter file path to notebook', layout=Layout(width='95%'), style=DescriptionStyle(d…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import nbformat\n",
    "import ipywidgets as widgets\n",
    "\n",
    "WIDGET_DEFAULTS = {\n",
    "    \"layout\": widgets.Layout(width=\"95%\"),\n",
    "    \"style\": {\"description_width\": \"initial\"},\n",
    "}\n",
    "\n",
    "WIDGET_LARGE = {\n",
    "    \"layout\": widgets.Layout(width=\"95%\", height=\"100px\"),\n",
    "    \"style\": {\"description_width\": \"initial\"},\n",
    "}\n",
    "\n",
    "file_path = widgets.Text(description=\"Enter file path to notebook\",\n",
    "                        **WIDGET_DEFAULTS)\n",
    "display(file_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:27:08.863298Z",
     "start_time": "2019-12-09T19:27:08.693396Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "./Process Masking.ipynb\n"
     ]
    }
   ],
   "source": [
    "print(file_path.value)\n",
    "from pathlib import Path\n",
    "nb = nbformat.read(file_path.value, as_version=4.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:27:20.312825Z",
     "start_time": "2019-12-09T19:27:20.302859Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'hide_input': False,\n",
       " 'kernelspec': {'display_name': 'Python 3',\n",
       "  'language': 'python',\n",
       "  'name': 'python3'},\n",
       " 'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 3},\n",
       "  'file_extension': '.py',\n",
       "  'mimetype': 'text/x-python',\n",
       "  'name': 'python',\n",
       "  'nbconvert_exporter': 'python',\n",
       "  'pygments_lexer': 'ipython3',\n",
       "  'version': '3.7.3'},\n",
       " 'toc': {'base_numbering': 1,\n",
       "  'nav_menu': {},\n",
       "  'number_sections': False,\n",
       "  'sideBar': True,\n",
       "  'skip_h1_title': False,\n",
       "  'title_cell': 'Table of Contents',\n",
       "  'title_sidebar': 'Contents',\n",
       "  'toc_cell': False,\n",
       "  'toc_position': {},\n",
       "  'toc_section_display': True,\n",
       "  'toc_window_display': False},\n",
       " 'varInspector': {'cols': {'lenName': 16, 'lenType': 16, 'lenVar': 40},\n",
       "  'kernels_config': {'python': {'delete_cmd_postfix': '',\n",
       "    'delete_cmd_prefix': 'del ',\n",
       "    'library': 'var_list.py',\n",
       "    'varRefreshCmd': 'print(var_dic_list())'},\n",
       "   'r': {'delete_cmd_postfix': ') ',\n",
       "    'delete_cmd_prefix': 'rm(',\n",
       "    'library': 'var_list.r',\n",
       "    'varRefreshCmd': 'cat(var_dic_list()) '}},\n",
       "  'types_to_exclude': ['module',\n",
       "   'function',\n",
       "   'builtin_function_or_method',\n",
       "   'instance',\n",
       "   '_Feature'],\n",
       "  'window_display': False}}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nb[\"metadata\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:27:27.235900Z",
     "start_time": "2019-12-09T19:27:27.229906Z"
    }
   },
   "outputs": [],
   "source": [
    "DEF_KERNELSPEC = {\n",
    "    \"name\": \"python36\",\n",
    "    \"display_name\": \"Python 3.6\",\n",
    "    \"language\": \"python\"\n",
    "}\n",
    "\n",
    "DEF_DATASOURCES = [\n",
    "    \"SecurityAlert\",\n",
    "    \"SecurityEvent\",\n",
    "    \"HuntingBookmark\",\n",
    "    \"Syslog\",\n",
    "    \"AAD SigninLogs\",\n",
    "    \"AzureActivity\",\n",
    "    \"OfficeActivity\",\n",
    "    \"ThreatIndicator\",\n",
    "    \"VirusTotal (API key required)\",\n",
    "    \"AlienVault OTX (API key required)\",\n",
    "    \"IBM XForce (API key required)\",\n",
    "    \"Open Page Rank (API key required)\"\n",
    "]\n",
    "\n",
    "DEF_PLATFORMS = [\n",
    "    \"Azure Notebooks Free Compute\",\n",
    "    \"Azure Notebooks DSVM\",\n",
    "    \"OS Independent\"\n",
    "]\n",
    "\n",
    "DEF_PYVERSION = \"Python 3.6 (including Python 3.6 - AzureML)\"\n",
    "\n",
    "AS_META_KEY = \"azure.azuresentinel\"\n",
    "\n",
    "as_metadata = nb[\"metadata\"].get(AS_META_KEY, {})\n",
    "ks_metadata = nb[\"metadata\"].get(\"kernelspec\", {})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:27:38.776161Z",
     "start_time": "2019-12-09T19:27:38.731212Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1a6e6b084971420c86456a6eaf66378f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(Text(value='', layout=Layout(width='95%'), placeholder='notebook title', style=DescriptionStyle…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "kernel_version = widgets.Text(\n",
    "                     value=ks_metadata.get(\"name\", DEF_KERNELSPEC[\"name\"]),\n",
    "                     **WIDGET_DEFAULTS)\n",
    "kernel_version_name = widgets.Text(\n",
    "                     value=ks_metadata.get(\"display_name\", DEF_KERNELSPEC[\"display_name\"]),\n",
    "                     **WIDGET_DEFAULTS)\n",
    "kernel_lang = widgets.Text(\n",
    "                     value=ks_metadata.get(\"language\", DEF_KERNELSPEC[\"language\"]),\n",
    "                     **WIDGET_DEFAULTS)\n",
    "\n",
    "title = widgets.Text(placeholder=\"notebook title\",\n",
    "                     value=as_metadata.get(\"title\"),\n",
    "                     **WIDGET_DEFAULTS)\n",
    "description = widgets.Textarea(placeholder=\"notebook description\",\n",
    "                               value=as_metadata.get(\"description\"),\n",
    "                               **WIDGET_LARGE)\n",
    "nbversion = widgets.Text(\n",
    "                         value=as_metadata.get(\"nbversion\", \"1.0\"),\n",
    "                         **WIDGET_DEFAULTS)\n",
    "pyversion = widgets.Text(\n",
    "                         value=as_metadata.get(\"pyversion\", DEF_PYVERSION),\n",
    "                         **WIDGET_DEFAULTS)\n",
    "platforms = widgets.Textarea(\n",
    "                             value=\"\\n\".join(as_metadata.get(\"platforms\", DEF_PLATFORMS)),\n",
    "                             **WIDGET_LARGE)\n",
    "datasources = widgets.Textarea(\n",
    "                               value=\"\\n\".join(as_metadata.get(\"datasources\", DEF_DATASOURCES)),\n",
    "                               **WIDGET_LARGE)\n",
    "display(widgets.VBox([\n",
    "    title,\n",
    "    description,\n",
    "    nbversion,\n",
    "    pyversion,\n",
    "    platforms,\n",
    "    datasources,\n",
    "    kernel_version,\n",
    "    kernel_version_name,\n",
    "    kernel_lang,\n",
    "    ]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-09T19:27:53.436250Z",
     "start_time": "2019-12-09T19:27:53.375284Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ec050e70f5384d79a657276d85583cf4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(VBox(children=(Label(value='Title'), Label(value='Description', layout=Layout(height='100px', w…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "wgt_vbox = widgets.VBox(\n",
    "    [\n",
    "        title,\n",
    "        description,\n",
    "        nbversion,\n",
    "        pyversion,\n",
    "        platforms,\n",
    "        datasources,\n",
    "        kernel_version,\n",
    "        kernel_version_name,\n",
    "        kernel_lang,\n",
    "    ],\n",
    "    layout=widgets.Layout(width=\"75%\")\n",
    ")\n",
    "lbl_vbox = widgets.VBox(\n",
    "    [\n",
    "        widgets.Label(\"Title\"),\n",
    "        widgets.Label(\"Description\", **WIDGET_LARGE),\n",
    "        widgets.Label(\"Notebook version\"),\n",
    "        widgets.Label(\"Supported Python versions\"),\n",
    "        widgets.Label(\"Supported Platforms\", **WIDGET_LARGE),\n",
    "        widgets.Label(\"Data Sources\", **WIDGET_LARGE),\n",
    "        widgets.Label(\"Kernel version\",),\n",
    "        widgets.Label(\"Kernel name\"),\n",
    "        widgets.Label(\"Kernel version\"),\n",
    "    ], \n",
    "    layout=widgets.Layout(width=\"25%\"))\n",
    "display(widgets.HBox([lbl_vbox, wgt_vbox]))"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
